﻿using AutoMapper;
using SIG.Service;
using SIG.ViewModel.Front.Pages;
using SIG.WebMVC.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace SIG.WebMVC.Controllers
{
    public class PageController : BaseController
    {
        private readonly IPageService _pageService;
        private readonly IPageMetaService _pageMetaService;
        private readonly IMapper _mapper;

        public PageController(IPageService pageService, IPageMetaService pageMetaService, IMapper mapper)
        {
            _pageService = pageService;
            _pageMetaService = pageMetaService;
            _mapper = mapper;

        }
        [Route("page-{seoName}")]
        [SIGActionFilter]
        // GET: Page
        public ActionResult Index(string seoName)
        {
            var page = _pageService.GetPageBySeoName(seoName);
            
            if (page == null)
                return HttpNotFound();

            var pageMeta = _pageMetaService.GetPageMeta(Model.Enums.ModelType.PAGE, page.Id);
            PageVM vm = new PageVM()
            {
                Id = page.Id,
                Title = page.Title,
                Body = page.Body,
                Keyword = pageMeta != null ? pageMeta.Keyword : "",
                Description = pageMeta != null ? pageMeta.Description : ""
            };
            return View(vm);
        }
    }
}